﻿using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class Turn : MonoBehaviour {

	public int Velocity = 1,status = 1;//旋转速度与旋转状态
	public bool Swtich = true;	//旋转开关
	public Image BgImage;

	// Use this for initialization
	void Start () {
		BgImage.sprite = GameObject.FindGameObjectWithTag ("BG").GetComponent<BGImage> ().OnGetBG ();
	}
	
	// Update is called once per frame
	void Update () {
	
		if (Swtich) 
		{
			if (status == 1) 
			{
				transform.Rotate (0,0,-Velocity*Time.deltaTime);
			}
			else if (status == 2) 
			{
				transform.Rotate (0,0,Velocity*Time.deltaTime);
			}
		}
	}

	void Reset(int level)
	{
		Velocity = 20 +5* ((level-1) / 3 );
		status = ((level - 1) / 3) % 2 + 1;
	}

	/// <summary>
	/// Raises the play event.
	/// </summary>
	public void OnPlay()
	{
		Swtich = true;
	}

	/// <summary>
	/// Raises the stop event.
	/// </summary>
	public void OnStop()
	{
		Swtich = false;
	}

	public void OnGameBack()
	{
		SceneManager.LoadScene (1);
	}
}
